<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ include file="/page/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<%@ include file="/adapter/adapter-bootstrap.jsp"%>
<link
	href="${pageContext.request.contextPath}/frontframe/easyui/themes/easyui-extend.css"
	rel="stylesheet" type="text/css" />
<script type="text/javascript">
	function save() {
		var str_data = $("#form1 input,textarea").map(function() {
			return ($(this).attr("name") + '=' + $(this).val().replace(/&/g,"~"));
		}).get().join("&");
		$.ajax({
			url : "${ctx}/appwxRespAction/updatewxRespAction",
			type : "POST",
			dataType : "json",
			data : str_data,
			async : false,
			success : function(data) {
				if (data.flag > 0) {
					alert("修改成功！");
					//window.location.reload();
				}
				/* 	          $.each(data, function(index, element) {
				 window.location.reload();
				 }); */
			},
			error : function() {
				alert("error");
			}
		});

	}

	function changeValue(Value, tagname) {
		document.getElementById(tagname).value = Value;
	}

	function goBack() {
		window.history.back(-1);
	}
	
	
	//用一个隐藏的input和select联动来实现选择使用挡板
	 function changetype(aThis){
			document.getElementById("wx_resp_type").value=aThis.value;
			if(aThis.value==1){
				$("#wx_resp_text").attr("disabled",true);
			}else{
				$("#wx_resp_text").attr("disabled",false);
			}
	}
	 //页面加载时给select预选值
	window.onload=function(){
		var menu_type="${appwxRespAction.wx_resp_type}";
		document.getElementById("wx_resp_type").value=menu_type;
		var all_options = document.getElementById("type_select").options;
		for (var i=0; i<all_options.length; i++){
			if (all_options[i].value == menu_type){
				all_options[i].selected = true;
			}
		}
		if(menu_type==1){
			$("#wx_resp_text").attr("disabled",true);
		}
		
		//给textarea赋值，将换行符转义回来
		var text_area="${appwxRespAction.wx_resp_text}".replace(/<br>/g,"\n");
		$("#wx_resp_text").val(text_area);
	}
	
</script>
</head>
<body>
	<div class="panel panel-default">
		<div class="panel-heading">
			<h3 class="panel-title">微信动作响应</h3>
		</div>
		<div class="panel-body">
			<form class="form-horizontal" role="form" id="form1">
				<div class="form-group">

					<label class="col-xs-2 control-label" for="wx_resp_actionid">动作编号</label>
					<div class="col-xs-4">
						<input class="form-control" id="wx_resp_actionid"
							name="wx_resp_actionid" type="text" placeholder="对于自动回复，为用户发送的消息" readonly="readonly"
							value="${appwxRespAction.wx_resp_actionid}" />
					</div>
					<label class="col-xs-2 control-label" for="app_id">应用ID</label>
					<div class="col-xs-4">
						<input class="form-control" id="app_id" name="app_id" type="text" readonly="readonly"
							placeholder="" value="${appwxRespAction.app_id}" />
					</div>
					
					

				<!--  
					<label class="col-xs-2 control-label" for="wx_resp_type">动作类型</label>
					<div class="col-xs-4">
						<input class="form-control" id="wx_resp_type" name="wx_resp_type"
							type="text" placeholder=""
							value="${appwxRespAction.wx_resp_type}" />
					</div>
				-->
				</div>
				<div class="form-group">
					<label class="col-xs-2 control-label" for="wx_resp_type">动作类型</label>
                          <div class="col-xs-4">
                             <input class="form-control" id="wx_resp_type" name="wx_resp_type" type="hidden" />
                             <select id="type_select"  onchange="changetype(this)" class="form-control">
                             	<option value='0'>纯文本</option>
                             	<option value='1'>图文</option>
                             </select>
                          </div> 
				</div>
				<div class="form-group">
					<label class="col-xs-2 control-label" for="wx_resp_text">响应文本</label>
					<div class="col-xs-10">
						<textarea rows="8" class="form-control" id="wx_resp_text" name="wx_resp_text" placeholder="纯文本类型必输，返回的文本内容,回车换行"  
						/></textarea>
					</div>
				</div>
				
				<div class="form-group  text-center">
					<button type="button" class="btn btn-default" onclick="save();">保存</button>
					<button type="button" class="btn btn-default" onclick="goBack()">返回</button>
				</div>
			</form>
		</div>
	</div>

</body>
</html>
